﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Services;

namespace BlueCMS.Core.Entities
{
    public class ActionNode
    {
        public Node node { get; set; }
        public Node parent { get; set; }
        public Action action { get; set; }
        public Plugin plugin { get; set; }

        public string Control
        { 
            get 
            { 
                return "~/_Plugins/" + plugin.folder + "/Actions/" + action.control; 
            } 
        }

        public bool CurrentUserHasPermission()
        {
            return UserHasPermission(CmsApplication.CmsUser);
        }

        public bool UserHasPermission(User user)
        {
            return UserService.UserHasPermissionForNode(user, "NODE", "VIEW", node)
                && UserService.UserHasPermissionForNode(user, "NODE", "EDIT", parent);
        }
    }
}
